﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head><link rel="stylesheet" href="${ctx}/common/common.css">
    <title>Title</title>
    <link href="${ctx}/common/plugins/tableTree/layui/css/layui.css" rel="stylesheet" />
    <script src="${ctx}/common/plugins/tableTree/jquery-1.10.2.min.js"></script>
    <script src="${ctx}/common/plugins/tableTree/layui/layui.js"></script>
</head>
<body>
<!--主体内容层-->
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12 layui-col-space15">
            <div class="layui-btn-group demoTable" style="float:right;" >
                <button class="layui-btn layui-btn-sm" onclick="addProductClassify()" data-type="addEnterprise">
                    <i class="layui-icon">&#xe654;</i>
                </button>
            </div>
            <%--tableTree生成位置--%>
            <div id="productClassifyTree" class="grid" style="margin-top: 20px"></div>
        </div>
    </div>
</div>
    <script id="view" type="text/html">
        <table class="layui-table">
            <thead>
            <tr>
                <th>产品类别</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {{# layui.each(d.rows,function(index,r){ }}
            <tr>
                <td>{{r.name}}</td>
                <td>{{r.create_time}}</td>
                <!--操作按钮-->
                <td class="text-center">
                    <a class="layui-btn layui-btn-small layui-btn-warm" href="javascript:fn.viewProCla('{{r.id}}')"><i></i>查看</a>
                    <a class="layui-btn layui-btn-small layui-btn-normal" href="javascript:fn.update('{{r.id}}')"><i></i>编辑</a>
                    <a class="layui-btn layui-btn-small layui-btn-danger" href="javascript:fn.delete('{{r.id}}')"><i></i>删除</a>
                </td>
            </tr>
            {{# }); }}
            </tbody>
        </table>
    </script>
</body>
<script>

    layui.config({
        base: '${ctx}/common/plugins/tableTree/extend/'
    }).use(['laytpl', 'treegrid'], function () {
        var laytpl = layui.laytpl,
            treegrid = layui.treegrid;
        treegrid.config.render = function (viewid, data) {
            var view = document.getElementById(viewid).innerHTML;
            return laytpl(view).render(data) || '';
        };
        var rows = ${json};
        var tree1=treegrid.createNew({
            elem: 'productClassifyTree',
            view: 'view',
            data: { rows: rows },//在这里赋值
            parentid: 'pid',
            singleSelect: true
        });
        tree1.build();
    });
    var fn={
    	viewProCla:function(id){
            window.location.href='${ctx}/productClassify/view/'+id
        },
        update:function(id){
            window.location.href='${ctx}/productClassify/update/'+id
        },
        delete:function(id){
        	layer.confirm("确认删除?", function () {
                $.post("${ctx}/productClassify/delete",{id:id},function(data){
                    if(data == '0'){
                        layer.alert("删除成功");
                        window.setTimeout(function(){window.location.reload()},2000)
                    }else{
                        layer.alert("删除失败");
                    }
                },"text")
            })
        }
    }
    function addProductClassify(){
        window.location.href='${ctx}/productClassify/create'
    }
</script>
</html>



